/**
 * Created with IntelliJ IDEA
 * Description:
 * User: Administrator
 * Data: 2023 - 08 - 08
 * Time: 15:18
 */




import java.math.BigDecimal;

import java.sql.Connection;

import java.sql.PreparedStatement;

import java.sql.SQLException;



class UpdateBook {



    /**

     * 修改图书《深入理解Java虚拟机》的价格为61.20

     */

    public static void main(String[] args) {

        Connection    connection    = null;

        PreparedStatement preparedStatement = null;

        try {

            connection = Util.getConnection();

            String sql = "update book set price=? where name =?";

            preparedStatement = connection.prepareStatement(sql);

            preparedStatement.setBigDecimal(1, new BigDecimal("60.20"));

            preparedStatement.setString(2, "深入理解Java虚拟机");

            System.out.println(preparedStatement);

            int result = preparedStatement.executeUpdate();

            System.out.println(result);

        } catch (SQLException e) {

            e.printStackTrace();

        } finally {

            Util.close(null, preparedStatement, connection);

        }

    }

}


